package com.kui.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kui.entity.Folder;
import com.kui.entity.User;
import com.kui.service.FolderService;
import com.kui.util.DateUtil;
import com.kui.util.UUUtil;

public class AddFolderServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.getRequestDispatcher("WEB-INF/views/addfolder.jsp").forward(request, response);
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			HttpSession session = request.getSession();
			User user = (User) session.getAttribute("user");
			String name = request.getParameter("foldername");
			FolderService fs = new FolderService();
		
			Folder f = new Folder();
			f.setCreatetime(DateUtil.getNow());
			f.setId(UUUtil.getUUID());
			f.setName(name);
			f.setT_user_id(user.getId());
			
			fs.addFolder(f);
			response.sendRedirect("folder.jspx");
	}

}
